package com.aggron.common;

import com.aggron.entity.SysUser;

import javax.servlet.http.HttpServletRequest;

/**
 * request局部线程类
 * @author  liuhuan on 2018/6/4.
 */
public class RequestHolder {
    private final static ThreadLocal<SysUser> SYS_USER_THREAD_LOCAL=new ThreadLocal<SysUser>();
    private final static ThreadLocal<HttpServletRequest> REQUEST_THREAD_LOCAL=new ThreadLocal<HttpServletRequest>();
    private final static ThreadLocal<String> TOKEN_THREAD_LOCAL=new ThreadLocal<String>();

    public static  void addUserName(SysUser sysUser){
        SYS_USER_THREAD_LOCAL.set(sysUser);
    }
    public static  void addRequest(HttpServletRequest httpServletRequest){
        REQUEST_THREAD_LOCAL.set(httpServletRequest);
    }
    public static  void addToken(String token){
        TOKEN_THREAD_LOCAL.set(token);
    }
    public static SysUser getCurrentUser(){
        return SYS_USER_THREAD_LOCAL.get();
    }
    public static HttpServletRequest getResquest(){
        return REQUEST_THREAD_LOCAL.get();
    }
    public static String getToken(){
        return TOKEN_THREAD_LOCAL.get();
    }

    public static void remove(){
        SYS_USER_THREAD_LOCAL.remove();
        REQUEST_THREAD_LOCAL.remove();
        TOKEN_THREAD_LOCAL.remove();
    }
}
